Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Data.SqlClient

Namespace MyDAO
    Public Class DeleteStringBuilder
        Inherits SqlStringBuilder

        Public Sub New(ByVal tableName As String)
            MyBase.New(tableName, "")
        End Sub

        Public Sub New(ByVal tableName As String, ByVal aliasName As String)
            MyBase.New(tableName, aliasName)
        End Sub

        Public Overrides Function Build() As MyStringBuilder
            Dim sql As New MyStringBuilder

            If Me.Table.AliasName = "" Then
                sql.AppendFormat("delete from {0} ", Me.Table)
            Else
                sql.AppendFormat("delete {0} from {1} ", Me.Table.AliasName, Me.Table)
            End If

            Dim expressions As New List(Of String)

            'join
            expressions.Clear()

            For Each relation As MyDataRelationBase In Me.Relations
                'sql.AppendFormat("
                expressions.Add(relation.ToString())
            Next

            sql.AppendFormat(String.Join(" ", expressions.ToArray()))
            sql.AppendFormat(" ")

            'condition
            If Me.Condition IsNot Nothing Then
                sql.AppendFormat("where ")
                sql.AppendFormat(Me.Condition.ToString())
            End If

            Return sql
        End Function

    End Class
End Namespace
